home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jedit_io.tcl < prev    next >
Encoding:
Text File  |  1995-02-08  |  4.4 KB  |  135 lines

  1. # jedit_io.tcl - file access procedures for jedit, a tk-based editor
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5.  
  6. # TO DO
  7. #   abbrev fixes:
  8. #     maybe some heuristics for things like plurals
  9. #     maybe a syntax for suffixes (e.g., commit;t -> commitment)
  10. #   file_modes panel
  11. #   documentation for keybindings (automatic documentation?)
  12. #   problem with filename getting set when you cancel Save 
  13. #     for the first time on a new unnamed file
  14. #   improve find panel
  15. #     have find wrap around (if last time didn't match)
  16. #     regex search/replace
  17. #     find all at once (mark) and cycle through with tag nextrange
  18. #   gesture commands
  19. #   autobreaking space a problem if you use two spaces betw sentences
  20. #   word-end punctuation (and heuristics) sd be mode-specific
  21. #
  22. #   PROBLEM WITH CHANGING BINDINGS ON THE FLY!               (urgent)
  23.  
  24. # CHANGES:
  25. #   lots of binding changes (jbind*.tcl consistency)
  26. #     app-specific Emacs and vi bindings
  27. #   house(s) the s won't expand
  28. #   return key checkpoints!
  29. #   improved mode handling (hooks)
  30.  
  31. ######################################################################
  32.  
  33. ######################################################################
  34. # "Load..." with supplied filename
  35. ######################################################################
  36.  
  37. proc jedit:read { filename t } {
  38.   global JEDIT_MODEPREFS
  39.   set mode [jedit:get_mode $t]
  40.   if {! [info exists JEDIT_MODEPREFS($mode,savestate)]} {
  41.     set JEDIT_MODEPREFS($mode,savestate) 0
  42.   }
  43.   set mode [jedit:get_mode $t]
  44.  
  45.   if {[info procs mode:$mode:pre_read_hook] != {}} {
  46.     mode:$mode:pre_read_hook $filename $t
  47.   }
  48.   if {[info procs mode:$mode:read] != {}} {
  49.     mode:$mode:read $filename $t
  50.   } else {
  51.     if {! [file exists $filename]} then {
  52.       jedit:cmd:save_checkpoint $t        ;# in case you were editing sth
  53.       j:text:delete $t 1.0 end
  54.       j:text:move $t 1.0
  55.       jedit:set_label [jedit:text_to_top $t] "$filename (new file)"
  56.     } else {
  57.       jedit:cmd:save_checkpoint $t        ;# so you can undo a load
  58.       # should do error checking
  59.       j:text:delete $t 1.0 end
  60.       $t insert end  [j:fileio:read $filename]
  61.       j:text:move $t 1.0
  62.       #
  63.       if $JEDIT_MODEPREFS($mode,savestate) {
  64.         jedit:read_annotation $filename $t
  65.         jedit:yview_insert $t
  66.       }
  67.       jedit:cmd:save_checkpoint $t        ;# alows undo to original state
  68.     }
  69.   }
  70.   jedit:set_label [jedit:text_to_top $t]    ;# display name over text field
  71.   if {[info procs mode:$mode:post_read_hook] != {}} {
  72.     mode:$mode:post_read_hook $filename $t
  73.   }
  74. }
  75.  
  76. ######################################################################
  77. # write out a file
  78. ######################################################################
  79.  
  80. proc jedit:write { filename t } {
  81.   global JEDIT_MODEPREFS
  82.   set mode [jedit:get_mode $t]
  83.   if {! [info exists JEDIT_MODEPREFS($mode,savestate)]} {
  84.     set JEDIT_MODEPREFS($mode,savestate) 0
  85.   }
  86.   set mode [jedit:get_mode $t]
  87.   
  88.   if {[info procs mode:$mode:pre_write_hook] != {}} {
  89.     mode:$mode:pre_write_hook $filename $t
  90.   }
  91.   if {[info procs mode:$mode:write] != {}} {
  92.     mode:$mode:write $filename $t
  93.   } else {
  94.     # should do error checking
  95.     j:fileio:write $filename [$t get 1.0 end]
  96.     jedit:set_label [jedit:text_to_top $t]
  97.     #
  98.     if $JEDIT_MODEPREFS($mode,savestate) {
  99.       jedit:write_annotation $filename $t
  100.     }   
  101.   }
  102.   if {[info procs mode:$mode:post_write_hook] != {}} {
  103.     mode:$mode:post_write_hook $filename $t
  104.   }
  105. }
  106.  
  107. ######################################################################
  108. # write out non-text content of a file
  109. ######################################################################
  110.  
  111. proc jedit:write_annotation { filename t } {
  112.   set dirname [file dirname $filename]
  113.   set tail [file tail $filename]
  114.   set filename "$dirname/.state.$tail"
  115.   # should do error checking
  116.   j:fileio:write $filename [j:tag:get_annotation $t]
  117. }
  118.  
  119. ######################################################################
  120. # restore non-text content of a file
  121. ######################################################################
  122.  
  123. proc jedit:read_annotation { filename t } {
  124. ### NEEDS ERROR CHECKING!
  125.   set dirname [file dirname $filename]
  126.   set tail [file tail $filename]
  127.   set filename "$dirname/.state.$tail"
  128.   catch {
  129.     set state [j:fileio:read $filename]
  130.     j:tag:set_annotation $t $state
  131.   }
  132. }
  133.  
  134.